
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>MNIST手写识别</title>
  <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body class="bg-gradient-to-br from-blue-50 to-purple-50 min-h-screen">
  <div class="container mx-auto px-4 py-8">
    <header class="text-center mb-8">
      <h1 class="text-4xl font-bold text-purple-700 mb-2">MNIST手写数字识别</h1>
      <p class="text-gray-600">基于TensorFlow.js的卷积神经网络实现</p>
    </header>

    <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
      <!-- 绘图识别区 -->
      <div class="bg-white rounded-xl shadow-lg p-6">
        <h2 class="text-2xl font-semibold text-gray-800 mb-4">手写板</h2>
        <div class="flex flex-col items-center">
          <canvas id="drawingCanvas" width="280" height="280" 
                  class="border-2 border-gray-300 rounded-lg bg-black touch-none"></canvas>
          <div class="flex space-x-4 mt-4">
            <button id="predictBtn" class="px-6 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition">
              <i class="fas fa-brain mr-2"></i>识别数字
            </button>
            <button id="clearBtn" class="px-6 py-2 bg-gray-500 text-white rounded-lg hover:bg-gray-600 transition">
              <i class="fas fa-eraser mr-2"></i>清除画板
            </button>
          </div>
        </div>
      </div>

      <!-- 结果展示区 -->
      <div class="bg-white rounded-xl shadow-lg p-6">
        <h2 class="text-2xl font-semibold text-gray-800 mb-4">识别结果</h2>
        <div id="predictionResult" class="text-center py-8">
          <p class="text-gray-500">请在手写板绘制数字后点击识别</p>
        </div>
        <div class="mt-6">
          <h3 class="text-lg font-medium text-gray-700 mb-2">置信度分布</h3>
          <canvas id="confidenceChart" height="200"></canvas>
        </div>
      </div>
    </div>

    <!-- 模型训练区 -->
    <div class="bg-white rounded-xl shadow-lg p-6 mt-8">
      <h2 class="text-2xl font-semibold text-gray-800 mb-4">模型训练</h2>
      <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
        <div>
          <label class="block text-gray-700 mb-2">训练轮次</label>
          <input type="number" id="epochs" value="5" min="1" max="20" 
                 class="w-full px-3 py-2 border rounded-lg">
        </div>
        <div>
          <label class="block text-gray-700 mb-2">批次大小</label>
          <input type="number" id="batchSize" value="128" min="32" max="256" 
                 class="w-full px-3 py-2 border rounded-lg">
        </div>
        <div class="flex items-end">
          <button id="trainBtn" class="w-full px-6 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition">
            <i class="fas fa-cogs mr-2"></i>训练模型
          </button>
        </div>
      </div>
      <div id="trainingProgress" class="mt-4 hidden">
        <div class="flex justify-between mb-1">
          <span class="text-sm font-medium text-gray-700">训练进度</span>
          <span id="progressText" class="text-sm font-medium text-gray-700">0%</span>
        </div>
        <div class="w-full bg-gray-200 rounded-full h-2.5">
          <div id="progressBar" class="bg-blue-600 h-2.5 rounded-full" style="width: 0%"></div>
        </div>
      </div>
    </div>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.18.0/dist/tf.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  <script src="app.js"></script>
</body>
</html>
